<?php
namespace app\index\validate;

use think\Validate;

class CrmAddProject extends Validate
{
    protected $rule = [
        's_type'     => 'in:1,2,3,4,5,6,7,8|require',
//        'identification' => 'require',
        'project_name' => 'require',
        'contact' => 'require',
        'phone'      =>  'checkPhone|require',
         /* 'email' => 'email|require', */
        'follow_status' => 'require',
        'customer' => 'require',
    ];

    protected $message  =   [
        's_type.in' => '类型不对',
        's_type.require' => '类型不能为空',
        'identification.require' => '唯一标识不能为空',
        'project_name.require' => '项目名称不能为空',
        'contact.require' => '联系人不能为空',
        'phone.mobile' => '请输入正确的手机号',
        'phone.require' => '手机号不能为空',
        /* 'email.email' => 'email格式不对',
        'email.require' => 'email不能为空',  */
        'follow_status.require' => '跟踪状态不能为空',
        'customer.require' => '客户类型不能为空',
        'is_monitor.require' => '是否监控不能为空',
        'is_monitor.in' => '是否监控取值范围不对'
    ];

    /**
     * @param $value
     * @param $rule
     * @param array $data
     * @return bool|string
     */
    protected function checkPhone($value,$rule,$data=[])
    {
        $search = '/^0?1[3|4|5|6|7|8][0-9]\d{8}$/';
        if (preg_match($search,$value)){
            return $rule = true;
        }else{
            return $rule = '请输入正确的手机号';
        }
    }
}